package com.ws.system.userrole.service.impl;

import com.ws.common.base.BaseUtils;
import com.ws.common.result.entity.ResultEntity;
import com.ws.system.user.entity.SystemUser;
import com.ws.system.userrole.entity.SystemUserrole;
import com.ws.system.userrole.mapper.SystemUserroleMapper;
import com.ws.system.userrole.service.ISystemUserroleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import com.ws.common.utils.PageUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author weifucheng
 * @since 2019-11-08
 */
@Service
public class SystemUserroleServiceImpl extends ServiceImpl<SystemUserroleMapper, SystemUserrole> implements ISystemUserroleService {

    @Override
    public Page<SystemUserrole> list(SystemUserrole systemUserrole, Integer current, Integer size) {
        Page<SystemUserrole> page= PageUtils.newPage(current, size);
        page.setRecords(baseMapper.listByParam(page,systemUserrole));
        return page;
    }

    @Override
    public Boolean updateById(String roleId, Boolean checked, String userId) {
        SystemUserrole userrole=new SystemUserrole();
        userrole.setUserId(userId);
        userrole.setRoleId(roleId);
        if(checked==true){
            BaseUtils.setDefault(userrole);
            return this.save(userrole);
        }else{
            List<SystemUserrole> userroles=baseMapper.listByParam(userrole);
            if(userroles.size()>0){
                return this.removeById(userroles.get(0).getId());
            }
            return true;
        }
    }
}
